#include "util_canvas.h"
#include "xtypes.h"


void CxCanvas::Resize( int_t nWidth, int_t nHeight )
{
	m_Array2.SetCaps(nWidth, nHeight);
}

void CxCanvas::SetBGColor( xColor c )
{
	m_BGColor = c;
}

void CxCanvas::Clear()
{
	m_Array2.Clear(m_BGColor);
}

void CxCanvas::Clear( xColor c )
{
	m_Array2.Clear(c);
}

int_t CxCanvas::GetWidth()
{
	return m_Array2.GetLimitX();
}

int_t CxCanvas::GetHeight()
{
	return m_Array2.GetLimitY();
}

void CxCanvas::SetPixel( int_t x, int_t y, xColor c )
{
	m_Array2.SetElement(x, y, c);
}

xColor CxCanvas::GetPixel( int_t x, int_t y )
{
	return m_Array2.GetElement(x, y);
}

CxCanvas::CxCanvas() : m_BGColor(0)
{

}

CxCanvas::CxCanvas( int_t nWidth, int_t nHeight )
{
	Resize(nWidth, nHeight);
}

CxCanvas::~CxCanvas()
{

}

void CxPlaneCanvas::SetPixel( int_t x, int_t y, xColor c )
{
	if( x<0 || x>=GetWidth() || y<0 || y>=GetHeight() )
	{
		return;
	}

	m_Array2.SetElement(x, y, c);
}

xColor CxPlaneCanvas::GetPixel( int_t x, int_t y )
{
	if( x<0 || x>=GetWidth() || y<0 || y>=GetHeight() )
	{
		return m_BGColor;
	}

	return m_Array2.GetElement(x, y);
}

CxPlaneCanvas::CxPlaneCanvas()
{

}

CxPlaneCanvas::CxPlaneCanvas( int_t nWidth, int_t nHeight ) : CxCanvas(nWidth, nHeight)
{

}

CxPlaneCanvas::~CxPlaneCanvas()
{

}

void CxSphereCanvas::SetPixel( int_t x, int_t y, xColor c )
{
	int_t nWidth = GetWidth();
	int_t nHeight = GetHeight();
	x = (x% nWidth + nWidth) % nWidth;
	y = (y% nWidth + nHeight) % nHeight;

	m_Array2.SetElement(x, y, c);
}

xColor CxSphereCanvas::GetPixel( int_t x, int_t y )
{
	int_t nWidth = GetWidth();
	int_t nHeight = GetHeight();
	x = (x% nWidth + nWidth) % nWidth;
	y = (y% nWidth + nHeight) % nHeight;

	return m_Array2.GetElement(x, y);
}

CxSphereCanvas::CxSphereCanvas()
{

}

CxSphereCanvas::CxSphereCanvas( int_t nWidth, int_t nHeight ) : CxCanvas(nWidth, nHeight)
{

}

CxSphereCanvas::~CxSphereCanvas()
{

}
